
import {createModel} from "./model.js";
import {ø} from "../util/objects.js";
// import {mapObject} from "../lib/underscore.js";
import {mapObject} from "underscore";


export function initialSharedState() {
    return ø({
        mode: "air",                      // string: name of a mode
        projection_type: "orthographic",  // string: name of a supported projection
        orientation: undefined,           // {rotate: number[2], scale: number}

        time_cursor: "current",           // string: "current" or {year:, month:, day:, hour:, minute:}, always UTC
        z_level: "surface",               // string: name of a level
        animation_type: "wind",           // string: name of a supported animation type
        overlay_type: "wind",             // string: name of an overlay

        spotlight_coords: undefined,      // [λ, φ] coordinates of spotlight marker or undefined
        show_grid_points: false,          // boolean
        animation_enabled: true,          // boolean
    });
}

/**
 * @type {Model}
 */
export const sharedStore = createModel(mapObject(initialSharedState(), () => undefined));

export function restoreSharedStore() {
    sharedStore.save(initialSharedState());
}

// CONSIDER: these default values are closely tied with the hash fragment serializer's behavior (like the absence of
// "anim=off" means animation is enabled, and vice versa with grid=on. This is annoyingly coupled... Would also
// be affected if hd_enabled or other fields are added into the shared store.

// maybe stuff in here should be those attributes which can affect product loading. and everything else, like
// spotlight_coords, goes in a different store. the hash fragment maintainer is then tasked with watching and merging
// together the fields that are encoded in the hash
